// 导入axios实例中的AxiosResponse泛型接口
import type {AxiosResponse} from "axios";
//导入封装的axios请求方法
import request from "../requestMethod";
import type {
    AddressInfo,
    ChargeReqVO,
    GetWalletReqVO,
    LoginReqVO,
    RegisterReqVO,
    SetDefaultAddressReqVO
} from "@/interfaces/user";
import type {EditGoodsStatus, PageGoodsReqVO, ReleaseGoods} from "@/interfaces/goods";
import type {DoPayReqVO, GetBusinessOrder, PageOrdersReqVO, UpdateOrderStatusReqVO} from "@/interfaces/order";
import type {AddCart, DelCart, PageCartReqVO} from "@/interfaces/cart";
// 参数类型导入


//  如果是get请求不需要写method，post请求使用data请求体 默认封装的get
// post示例
//  export const login = (data) => request({ method: "post", url: '/login', data: data });

// get示例
//  export const getUserList = (params) => request({ url: '/users', params });

// put示例
//     export const getEdit = (data) => request({
//      method: "put",
//      data,
//      url: "users/" + data.uid + "/state/" + data.type,
//    })


/**
 * 登录接口
 * @param data
 */
export const useLoginApi = (data: LoginReqVO): Promise<AxiosResponse<any, any>> =>
    request({
        method: "POST",
        url: "/uniApp/user/login",
        data,
    })

export const useRegisterApi = (data: RegisterReqVO): Promise<AxiosResponse<any, any>> =>
    request({
        method: "POST",
        url: "/uniApp/user/register",
        data,
    })


export const useChargeApi = (data: ChargeReqVO): Promise<AxiosResponse<any, any>> =>
    request({
        method: "POST",
        url: "/admin/user/charge",
        data,
    })

export const useGetWalletApi = (data: GetWalletReqVO): Promise<AxiosResponse<any, any>> =>
    request({
        method: "POST",
        url: "/admin/user/wallet",
        data,
    })

export const useAddAddressApi = (data: AddressInfo): Promise<AxiosResponse<any, any>> =>
    request({
        method: "POST",
        url: "/uniApp/address/add",
        data,
    })

export const useEditAddressApi = (data: AddressInfo): Promise<AxiosResponse<any, any>> =>
    request({
        method: "POST",
        url: "/uniApp/address/edit",
        data,
    })

export const useSetDefaultAddressApi = (data: SetDefaultAddressReqVO): Promise<AxiosResponse<any, any>> =>
    request({
        method: "POST",
        url: "/uniApp/address/default",
        data,
    })

export const useGetUserAddressApi = (data: { userId: string }): Promise<AxiosResponse<any, any>> =>
    request({
        method: "POST",
        url: "/uniApp/address",
        data,
    })


export const useAddGoodsApi = (data: ReleaseGoods): Promise<AxiosResponse<any, any>> =>
    request({
        method: "POST",
        url: "/uniApp/goods/add",
        data,
    })

export const useEditGoodsApi = (data: ReleaseGoods): Promise<AxiosResponse<any, any>> =>
    request({
        method: "POST",
        url: "/uniApp/goods/edit",
        data,
    })

export const useEditGoodsStatusApi = (data: EditGoodsStatus): Promise<AxiosResponse<any, any>> =>
    request({
        method: "POST",
        url: "/uniApp/goods/status",
        data,
    })

export const usePageGoodsApi = (data: PageGoodsReqVO): Promise<AxiosResponse<any, any>> =>
    request({
        method: "POST",
        url: "/uniApp/goods",
        data,
    })

export const useDoPayApi = (data: DoPayReqVO): Promise<AxiosResponse<any, any>> =>
    request({
        method: "POST",
        url: "/uniApp/order/pay",
        data,
    })

export const useUpdateOrderStatusApi = (data: UpdateOrderStatusReqVO): Promise<AxiosResponse<any, any>> =>
    request({
        method: "POST",
        url: "/uniApp/order/status",
        data,
    })

export const usePageOrdersApi = (data: PageOrdersReqVO): Promise<AxiosResponse<any, any>> =>
    request({
        method: "POST",
        url: "/uniApp/order",
        data,
    })

export const useAddCartApi = (data: AddCart): Promise<AxiosResponse<any, any>> =>
    request({
        method: "POST",
        url: "/uniApp/cart/add",
        data,
    })

export const useDelCartApi = (data: DelCart): Promise<AxiosResponse<any, any>> =>
    request({
        method: "POST",
        url: "/uniApp/cart/del",
        data,
    })

export const usePageCartApi = (data: PageCartReqVO): Promise<AxiosResponse<any, any>> =>
    request({
        method: "POST",
        url: "/uniApp/cart",
        data,
    })

export const useGetBusinessOrderApi = (data: GetBusinessOrder): Promise<AxiosResponse<any, any>> =>
    request({
        method: "POST",
        url: "/uniApp/order/business",
        data,
    })


// 如何在组件使用
/*
// post请求
import { login } from "@/api/api";
const { data: res } = await login(loginForm);
if (res.meta.status !== 200) return ELMessage.error("登录失败！");
ELMessage.success("登录成功！");
// 保存token
localStorage.setItem("token", res.data.token);
// 跳转到首页
router.push("/");
// 获取用户信息
getUserInfoList();
// get请求
import { getUserList } from "@/api/api";
const { data: res } = await getUserList({ pageNum: 1, pagesize: 2 });
if (res.meta.status !== 200) return ELMessage.error("获取分类列表失败！");
editCateForm = res.data;
editCateDialogVisible.value = true;
// put请求
import { getEdit } from "@/api/api";
const { data: res } = await getEdit({
  uid: row.uid,
  type: row.mg_state,
});
if (res.meta.status !== 200) return ELMessage.error("修改状态失败！");
ELMessage.success("修改状态成功！");
getUserList();
*/